package com.example.leetdemo.plan1;

public class Sword003 {

    public int[] countBits(int n) {
        if (n == 0) {
            return new int[]{0};
        }
        int[] re = new int[n + 1];
        re[0] = 0;
        int j = 1, k = j << 1;
        for (int i = 1; i <= n; i++) {
            if (i == k) {
                j = k; k = k << 1;
            }
            re[i] = re[i - j] + 1;
        }
        return re;
    }

    public static void main(String[] args) {
        Sword003 sword003 = new Sword003();
        int[] re = sword003.countBits(3);
        for (int i = 0; i < re.length; i++) {
            System.err.println(re[i] + " ");
        }
    }

}
